<?php

$route = $this->app->getRoute();

if ($this->entity->usetitle) {
    $attrib = "title";
} else {
    $attrib = "id";
}

$this->app->getDocument()->head->script->add('/entities/33/changeimages.js');

if ($this->entity->direction == 0) {
    $divorspan = "span";
} else {
    $divorspan = "div";
}



if ($this->entity->level == 0) {
    $navinum = 0;
} else {
     if (!isset($route[$this->entity->level-1])) {
        $navinum = -1;
    } else {
        $navinum = $route[$this->entity->level-1];
    }
}


if ($navinum != -1) {

    
    $menu = ent_navigationmenu::getBranch($this->app->getLangid(), $navinum);
            

    if ($menu->count()) {
                   
        print "<div class=\"navi_generic navi_level_" . $this->entity->level . "\">\n";
        $menuorder = 0;
        foreach ($menu as $key => $value) {
            $menuorder ++;
            if ($this->entity->showpics == 1) {
                $this->entity->images = $value->getImages();
            }

            if (!isset($route[$this->entity->level])) {
                $route[$this->entity->level] = 0;
            }

            if ($value->id == $route[$this->entity->level]) {

                if ($this->entity->showpics == 0) {
    
                    print "<$divorspan class=\"link_selected\">";
                    print $value->title;
                    print "</$divorspan>\n";
    
                } else {
    
                    print "<$divorspan class=\"link_selected\">";
                    print"<img alt=\"" . $value->title . "\" align=\"middle\"  title=\"" . $value->title . "\" name=\"img_" . $this->entity->id . "_" . $value->id . "\" src=\"";
                    if ($value->id != $route[$this->entity->level]) {
                        print $this->entity->images[0]->picfile->picpath;
                    } else {
                        print $this->entity->images[2]->picfile->picpath;
                    }
                    print "\" />";
                    print "</$divorspan>\n";
                }
            } else {
                if ($this->entity->showpics == 0) {
                    print "<$divorspan class=\"link_generic link_level_" . $this->entity->level . "\">";
                    print "<a href=\"$value->linkurl\">";
                    print $value->title;
                    print "</a>\n";
                    print "</$divorspan>\n";
                } else {
                    print "<$divorspan class=\"link_generic link_level_" . $this->entity->level . "\">\n";
                    print "<a href=\"$value->linkurl\"";
                    print " onmouseover=\"changeImages('img_" . $this->entity->id . "_" . $value->id . "', '" . $this->entity->images[1]->picfile->picpath . "'); return true;\" onmouseout=\"changeImages('img_" . $this->entity->id . "_" . $value->id . "', '" . $this->entity->images[0]->picfile->picpath . "'); return true;\">";
                    print"<img alt=\"" . $value->title . "\" align=\"middle\"  title=\"" . $value->title . "\" name=\"img_" . $this->entity->id . "_" . $value->id . "\" src=\"";
    
                    if ($value->id != $route[$this->entity->level]) {
                        print $this->entity->images[0]->picfile->picpath;
                    } else {
                        print $this->entity->images[2]->picfile->picpath;
                    }
                    
                    print "\" />";
                    print "</a>\n";
                    print "</$divorspan>\n";
    
    
                }
           }

            if ($this->entity->direction == 0 AND $menuorder != $menu->count()) {
                print " " . $this->entity->separator . " ";
            }
        }

        print "</div>";

    }
}

